<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
	<%
	Object obj = application.getAttribute("contextPath");
	if (obj == null) {
		application.setAttribute("contextPath","http://"+request.getServerName() + ":" + request.getServerPort() + ((HttpServletRequest) request).getContextPath());
	}
	pageContext.setAttribute("ctx", request.getContextPath());
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="stylesheet" type="text/css" href="js/jqueryeasyui12/themes/bootstrap/easyui.css" />
<link rel="stylesheet" type="text/css" href="js/jqueryeasyui12/themes/icon.css" />
<script type="text/javascript" src="js/jqueryeasyui12/jquery.min.js"></script>
<script type="text/javascript" src="js/jqueryeasyui12/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/jqueryeasyui12/locale/easyui-lang-zh_CN.js"></script>
<style>
html,body{margin: 0px;width: 100%; height: 100%; padding: 0;}
#north-panel{font-family: Microsoft JhengHei,Microsoft YaHei,tahoma, Arial, "\5b8b\4f53", sans-serif;background:#F2F2F2;}
#north-panel #sysname{float:left;font-size: 24px;font-weight: bold;}
#tabs{font-family: Microsoft JhengHei,Microsoft YaHei,tahoma, Arial, "\5b8b\4f53", sans-serif;}
#west-panel{font-family: Microsoft JhengHei,Microsoft YaHei,tahoma, Arial, "\5b8b\4f53", sans-serif;}
</style>
<script type='text/javascript' src='<%=request.getContextPath()%>/js/ipebg/IPEBG.js'></script>
<script type="text/javascript">
	$(document).ready(function() {
		

		tabClose();			
		addTab1("首頁", "pages/common/system/default.html", "tree-file") ;
		
		
		$.ajax({
			type: "POST",
			url : '<%=request.getContextPath()%>/menuTree/tree.do',
			error : function(textStatus, errorThrown) {
				alert("請求失敗，請聯繫管理員！");
				//$.messager.alert('系統提示','系統錯誤(' + textStatus + '): '+errorThrown,'error');
			},
			success : function(data, textStatus) {
				var $div,$ul,$subMenu=$("#submenu"),url;
				alert(data);
				data = IPEBG.str2json(data);
				
				for(var i=0;i<data.length;i++){
					$div = $("<div title=\""+data[i].text+"\" iconCls=\"icon-blank\" class=\"cs-navi-tab\" style=\"padding:1px;overflow:auto\"><ul id=\"mytree"+data[i].text+"\" class=\"easyui-tree\"></ul></div>");
					$div.find("ul").tree({
						data:data[i].children,
						onClick : function(node){
							url=node.url.indexOf("?")==-1?(node.url+"?id="+node.id):(node.url+"&id="+node.id)
		        			addTab(node.text,url,"tree-file");
		        		}
					});
					$subMenu.append($div);
				}
				$subMenu.accordion({
					fit:true,
					border:false,
					animate:false
				});
			}
			});                        
   	


   	//获取当前时间
   	var date=new Date();
   	var Y=date.getFullYear();
   	var M=date.getMonth()+1;
   	if(M<10) M="0"+M;
   	var D=date.getDate();
   	if(D<10) D="0"+D;

   	var weekday=new Array(7);
   	weekday[0]="星期日";
   	weekday[1]="星期一";
   	weekday[2]="星期二";
   	weekday[3]="星期三";
   	weekday[4]="星期四";
   	weekday[5]="星期五";
   	weekday[6]="星期六";
   	$("#date").text(Y+"年"+M+"月"+D+"日 "+weekday[date.getDay()]);
});
	var curTab=undefined;
	function tabClose() {
		$(".tabs-inner").dblclick(function() {
			var subtitle = $(this).children(".tabs-closable").text();
			$('#tabs').tabs('close', subtitle);
		});
	}
	function addTab(subtitle, url, icon) {
		 if (!$('#tabs').tabs('exists', subtitle)) {
			    if($('#tabs').tabs('tabs').length>4){
			    	$.messager.alert('系統提示', '窗口打開超過五個，請關閉一些后繼續打開！', 'info');
			    }else{
			    if(url != undefined){
				$('#tabs').tabs('add', {
					title : subtitle,
					content : createFrame(url),
					closable : true,
					fit:true
				});
				curTab = subtitle;
			}
			    }
		} else { 
			$('#tabs').tabs('select', subtitle);//选中并刷新
			var currTab = $('#tabs').tabs('getSelected');
			if(url != undefined) {
				$('#tabs').tabs('update', {
					tab: currTab,
					options: {
						content: createFrame(url),
						title:subtitle
					}
				});
				curTab = subtitle;
			}
		 }  
		tabClose();
	}

	function addTab1(subtitle, url, icon) {
		if (!$('#tabs').tabs('exists', subtitle)) {
			$('#tabs').tabs('add', {
				title : subtitle,
				content : createFrame(url),
				closable : true,
				fit:true
			});
		} else {
			$('#tabs').tabs('select', subtitle);
			var currTab = $('#tabs').tabs('getSelected');
			var url = $(currTab.panel('options').content).attr('src');
			if(url != undefined) {
				$('#tabs').tabs('update',{
					tab:currTab,
					options:{
						closable:true,
						content:createFrame(url)
					}
				})
			}
		}
		tabClose();
	}      
	function createFrame(url) {
		var str = '<iframe scrolling="auto" frameborder="0"  src="' + url + '" style="width:100%;height:100%;"></iframe>';
		return str;
	}
</script>
<title>XXXXXX系統</title>
</head>
<body class="easyui-layout">
    <div id="north-panel" region="north" border="false" style="scroll:no;height:60px;">
    	<table style="width:100%;height:100%" border="0">
    		<tr>
    			<td style="width:60%"><div id="sysname">&nbsp;&nbsp;XXXXXX系統</div></td>
    			<td style="width:40%;font-weight: bold;" align="right">
    				<div style="margin-right: 40px;">
    					<span>今天是： </span>
    					<span id="date"></span>
    				</div>
    				<div style="margin-right: 40px;padding-top:5px;">
    					<span style="margin-right:10px;">您好，${realname }</span>
    					<a href="${ctx}/j_spring_security_logout" style="text-decoration: initial;">退出</a>
    				</div>
    			</td>
    		</tr>
    	</table>
    </div>
    <div region="center" style="overflow-y:hidden">
    	<div id="tabs" class="easyui-tabs" fit="true" border="false">
    	</div>
	</div>
    <div id="west-panel" region="west" hide="true" split="false" headerCls ="headcls" border="true" title="系统功能" style="width:210px;" resizable="false">
		<div id='submenu' width="180px">
		</div>
	</div>
	<div align="center" region="south" border="false" style="height:20px;background:#F2F2F2;padding:0px;overflow:hidden;padding-top:3px;">
       <font color="#000" face="Microsoft JhengHei,Microsoft YaHei,tahoma, Arial, sans-serif" style="font-size:12px;">CopyRight &copy; 2015 中原資訊服務處-系統開發中心&nbsp;&nbsp;版權所有</font>
	</div>
</body>
</html>